package org.linlinjava.litemall.db.service;

import com.github.pagehelper.PageHelper;
import org.linlinjava.litemall.db.dao.LitemallTenderMapper;
import org.linlinjava.litemall.db.domain.LitemallTender;
import org.linlinjava.litemall.db.domain.LitemallTenderExample;
import org.linlinjava.litemall.db.domain.LitemallTenderMsg;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 投标 服务提供
 * @program: mall
 * @author: youvy
 * @create: 2019-12-26 14:24
 **/
@Service
public class LitemallTenderService {
	@Resource
	private LitemallTenderMapper tenderMapper;

	public List<LitemallTender> list(Integer page, Integer pageSize, Integer userid,String sort,Integer status) {
		LitemallTenderExample example = new LitemallTenderExample();
		LitemallTenderExample.Criteria criteria = example.or();
		if (userid!=null){
			criteria.andUserIdEqualTo(userid);
		}
		if (sort != null && sort.length() > 0) {
			example.setOrderByClause(sort);
		}
		if (status!=null) {
			criteria.andStatusEqualTo(status);
		}

		PageHelper.startPage(page, pageSize);
		return tenderMapper.selectByExampleWithBLOBs(example);
	}

	public List<LitemallTenderMsg> brandList(Integer page, Integer pageSize, Integer brandId) {
		return tenderMapper.getTenderAndQuote(brandId);
	}

	public Integer brandListCount(Integer brandId) {
		return tenderMapper.getTenderAndQuoteCount(brandId);
	}

	public void insert(LitemallTender tender) {
		tenderMapper.insert(tender);
	}

	public void update(LitemallTender tender) {
		tenderMapper.updateByPrimaryKeyWithBLOBs(tender);
	}

	public void delete(Integer id) {
		tenderMapper.deleteByPrimaryKey(id);
	}
}
